package model

import "go.mongodb.org/mongo-driver/bson/primitive"

// 用户角色表
type UserRole struct {
	UserId string `json:"userId" bson:"userId"`
	RoleId string `json:"roleId" bson:"roleId"`
}

type UserRoleList []*UserRole

// 获取 userId 数组
func (u UserRoleList) GetUsers() []string {
	arr := []string{}
	for idx := range u{
		arr = append(arr, u[idx].UserId)
	}
	return arr
}

func (u UserRoleList) GetUserBsonIds() []*primitive.ObjectID {
	arr := []*primitive.ObjectID{}
	for idx := range u{
		bsonId, err := primitive.ObjectIDFromHex(u[idx].UserId)
		if err != nil {
			return nil
		}
		arr = append(arr, &bsonId)
	}
	return arr
}
